﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using QLXuongCNTT.Object;
using QLXuongCNTT.DataLayers;
namespace QLXuongCNTT.ControlLayers
{
    class ctrlPhieuDeNghi
    {
        dtlPhieuDeNghi dtPDN;
        DataTable tbPDN =new DataTable();
        objPhieuDeNghi phieudenghi;
        internal objPhieuDeNghi Phieudenghi
        {
          get { return phieudenghi; }
          set { phieudenghi = value; }
        }
        string error;

        public string Error
        {
            get { return error; }
            set { error = value; }
        }
        public ctrlPhieuDeNghi()
        {
            dtPDN = new dtlPhieuDeNghi();
            phieudenghi = new objPhieuDeNghi();
            error = "";
        }
         public void insertPhieuDeNghi()
        {
            dtPDN.insertpdn(phieudenghi);
           if (dtPDN.Error != "")
                error = dtPDN.Error;
        }
         dtlPhieuDeNghi dtPDN_nam;
         public void get_PhieuDeNghi(TreeView trv)
         {
             tbPDN = dtPDN.getPDN_nam();
             int sd = tbPDN.Rows.Count;
             foreach (DataRow r in tbPDN.Rows)
             {
                 //DataRow r = tbPN.Rows[i];
                 TreeNode node_nam = new TreeNode();
                 string nam = r[0].ToString();
                 node_nam.Text = "Năm " + nam;
                 node_nam.ImageIndex = 0;
                 DataTable pdn = dtPDN_nam.getPhieuDeNghi(int.Parse(nam));
                 foreach (DataRow rr in pdn.Rows)
                 {
                     string sopn = rr[0].ToString();
                     string tenpn = rr[4].ToString();
                     TreeNode node_pdn = new TreeNode();
                     node_pdn.Text = sopn;
                     node_pdn.Tag = sopn;
                     node_nam.Nodes.Add(node_pdn);
                     node_pdn.ImageIndex = 1;
                 }
                 //add nam
                 trv.Nodes.Add(node_nam);
             }
             error = dtPDN.Error;
           
        }
        public void DeletePDN()
        {
            dtPDN.DeletePDN(phieudenghi.Sophieu);
            error = dtPDN.Error;
        }
        public void UpdatePDN()
        {
            dtPDN.UpdatePDN(phieudenghi);
            error = dtPDN.Error;
        }
        public DataTable ThongTin_PDN()
        {

            return dtPDN.getPhieuDeNghi_sophieu(phieudenghi.Sophieu);
        }
    }
}
